import { IHotSearchParams } from '@/interface/hotSearch';
import * as request from './request';

export async function getAllHotSearches(body: IHotSearchParams) {
  try {
    const login = sessionStorage.getItem('login')?.toString();
    if (login === '1') {
      const data = await request.post(
        JSON.stringify(body),
        '/api/console/hotSearch/get',
      );
      return data;
    } else {
      return {};
    }
  } catch (e) {
    return e;
  }
}

export async function changeStatuHotSearches(body: { content: string }) {
  try {
    const data = await request.post(
      JSON.stringify(body),
      '/api/console/hotSearch/changeStatu',
    );
    return data;
  } catch (e) {
    return e;
  }
}

export async function clearTimes(body: { content: string }) {
  try {
    const data = await request.post(
      JSON.stringify(body),
      '/api/console/hotSearch/clear',
    );
    return data;
  } catch (e) {
    return e;
  }
}

export async function deleteHotSearch(body: { content: string }) {
  try {
    const data = await request.post(
      JSON.stringify(body),
      '/api/console/hotSearch/remove',
    );
    return data;
  } catch (e) {
    return e;
  }
}

export async function changeContent(body: {
  originContent: string;
  newContent: string;
}) {
  try {
    const data = await request.post(
      JSON.stringify(body),
      '/api/console/hotSearch/changeContent',
    );
    return data;
  } catch (e) {
    return e;
  }
}

export async function addHotSearch(body: { content: string; statu: 1 | 0 }) {
  try {
    const data = await request.post(
      JSON.stringify(body),
      '/api/console/hotSearch/add',
    );
    return data;
  } catch (e) {
    return e;
  }
}
